#include <algorithm>
#include <iostream>
using namespace std;
const int N = 10010;
int n, m;
int v[N], w[N];
int mem[N][N];
int dp[N][N];

int dfs(int x, int spv)
{
    if (x > n)
        return 0;
    if (mem[x][spv])
        return mem[x][spv];
    int sum = 0;
    if (spv < v[x])
        sum = dfs(x + 1, spv);
    else
        sum = max(dfs(x + 1, spv), dfs(x, spv - v[x]) + w[x]);
    mem[x][spv] = sum;
    return sum;
}
int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i] >> w[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (j < v[i])
                dp[i][j] = dp[i - 1][j];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j + v[i]]);
        }
    }
    return 0;
}
